package cn.iune.erp.baseinfo;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Aspect // 指定这是一个其切面
public class FileFactoryDaoAspect {

	@Autowired
	private IFileFactoryService fileFactoryService;

	// 指定切入点（增加）
	@Pointcut("execution(* cn.iune.erp.baseinfo.IFileFactoryDao.insert(..)) && args(obj)")
	public void insertPointCut(FileFactory obj) {
	}

	// 指定通知以及通知的范围
	@Transactional
	@Before("insertPointCut(obj)")
	public void beforeInsert(FileFactory obj) {
		fileFactoryService.beforeInsert(obj);
	}

	@Transactional
	@After("insertPointCut(obj)")
	public void afterInsert(FileFactory obj) {
		fileFactoryService.afterInsert(obj);
	}

	// 指定切入点（删除）
	@Pointcut("execution(* cn.iune.erp.baseinfo.IFileFactoryDao.delete(..)) && args(fID)")
	public void deletePointCut(String fID) {
	}

	// 指定通知以及通知的范围
	@Transactional
	@Before("deletePointCut(fID)")
	public void beforeDelete(String fID) {
		fileFactoryService.beforeDelete(fID);
	}

	// 指定切入点（修改）
	@Pointcut("execution(* cn.iune.erp.baseinfo.IFileFactoryDao.update(..)) && args(obj)")
	/*
	public void updatePointCut(FileFactory obj) {
		//下面这一行是没有用的，不会被输出
		System.out.println("---->>>>updatePointCut");
	}
	*/
	public void updatePointCut(FileFactory obj){}
	//public FileFactory updatePointCut(FileFactory obj){return obj;}

	// 指定通知以及通知的范围
	@Transactional
	@Around("updatePointCut(obj)")
	public FileFactory aroundUpdate(JoinPoint joinPoint, FileFactory obj) throws Throwable {

		System.out.println("环绕通知上。。。");
		FileFactory newObj = (FileFactory) ((ProceedingJoinPoint) joinPoint).proceed();
		System.out.println("环绕通知下。。。");

		return newObj;

	}

}
